<?
function utf8_to_tis620($string){
  $str = $string;
  $res = "";
  for ($i = 0; $i < strlen($str); $i++) {
    if (ord($str[$i]) == 224) {
      $unicode = ord($str[$i+2]) & 0x3F;
      $unicode |= (ord($str[$i+1]) & 0x3F) << 6;
      $unicode |= (ord($str[$i]) & 0x0F) << 12;
      $res .= chr($unicode-0x0E00+0xA0);
      $i += 2;
    } else {
      $res .= $str[$i];
    }
  }
  return $res;
}

function utf8_substr($str,$start_p,$len_p)   {   
  preg_match_all("/./u", $str, $ar);   
  
  if(func_num_args() >= 3) {   
    $end = func_get_arg(2);   
    return join("",array_slice($ar[0],$start_p,$len_p));   
  } else {   
    return join("",array_slice($ar[0],$start_p));   
  }   
}

function get_month_name($m){
    if($m == 1) return "มกราคม";
    if($m == 2) return "กุมภาพันธ์";
    if($m == 3) return "มีนาคม";
    if($m == 4) return "เมษายน";
    if($m == 5) return "พฤษภาคม";
    if($m == 6) return "มิถุนายน";
    if($m == 7) return "กรกฎาคม";
    if($m == 8) return "สิงหาคม";
    if($m == 9) return "กันยายน";
    if($m == 10) return "ตุลาคม";
    if($m == 11) return "พฤศจิกายน";
    if($m == 12) return "ธันวาคม";
  return "";
}

function remove_dir($dir)  
     {  
          if(is_dir($dir))  
          {  
               $dir = (substr($dir, -1) != "/")? $dir."/":$dir;  
               $openDir = opendir($dir);  
               while($file = readdir($openDir))  
               {  
                    if(!in_array($file, array(".", "..")))  
                    {  
                         if(!is_dir($dir.$file))  
                         {  
                              unlink($dir.$file);  
                         }  
                         else  
                         {  
                              remove_dir($dir.$file);  
                         }  
                    }  
               }  
               closedir($openDir);  
               rmdir($dir);  
          }  
     }
     
  function redirect_($url,$sec) {
    echo "<html><head>";
    echo "<meta http-equiv='refresh' content='$sec; URL=$url'>";
    echo "</head></html>";
    exit;
  }
  
function alert($msg) {
  echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
  echo "<script language = 'javascript'>";
  echo "alert('$msg')";
  echo "</script>";
}

//Nawattapon
function img_exists($folder , $img){
  if($img==''){
    return FALSE;
  }else if(file_exists($folder.'/'.$img)){
    return TRUE;
  }else{
    return FALSE;
  }
}
?>